<template>
  <div class="container">
    <div class="tips-title">1. 基础用法</div>
    <el-transfer v-model="value1" :data="data1"></el-transfer>
    <div class="tips-title">2. 可搜索 <span class="tips-explain">在数据多的情况下，对数据进行搜索和过滤</span></div>
    <el-transfer filterable :filter-method="filterMethod" filter-placeholder="请输入城市拼音" v-model="value2" :data="data2"></el-transfer>
    <div class="tips-title">3. 可自定义</div>
    <el-transfer
      style="text-align: left; display: inline-block"
      v-model="value3"
      filterable
      :left-default-checked="[2, 3]"
      :right-default-checked="[1]"
      :titles="['Source', 'Target']"
      :button-texts="['到左边', '到右边']"
      :format="{noChecked: '${total}',hasChecked: '${checked}/${total}'}"
      @change="handleChange"
      :data="data3">
      <span slot-scope="{ option }">{{ option.key }} - {{ option.label }}</span>
      <el-button class="transfer-footer" slot="left-footer" size="small">操作</el-button>
      <el-button class="transfer-footer" slot="right-footer" size="small">操作</el-button>
    </el-transfer>
  </div>
</template>
<script>
  export default {
    name: 'f-transfer',
    data() {
      const generateData1 = _ => {
        const data = [];
        for(let i = 1; i <= 15; i++) {
          data.push({
            key: i,
            label: `备选项 ${ i }`,
            disabled: i % 4 === 0
          });
        }
        return data;
      };

      const generateData2 = _ => {
        const data = [];
        const cities = ['上海', '北京', '广州', '深圳', '南京', '西安', '成都'];
        const pinyin = ['shanghai', 'beijing', 'guangzhou', 'shenzhen', 'nanjing', 'xian', 'chengdu'];
        cities.forEach((city, index) => {
          data.push({
            label: city,
            key: index,
            pinyin: pinyin[index]
          });
        });
        return data;
      };

      const generateData3 = _ => {
        const data = [];
        for (let i = 1; i <= 15; i++) {
          data.push({
            key: i,
            label: `备选项 ${ i }`,
            disabled: i % 4 === 0
          });
        }
        return data;
      };

      return {

        data1: generateData1(),
        value1: [1, 4],

        data2: generateData2(),
        value2: [],
        filterMethod(query, item) {
          return item.pinyin.indexOf(query) > -1;
        },

        data3: generateData3(),
        value3: [1]
      }
    },
    methods: {
      handleChange(value, direction, movedKeys) {
        console.log('方向direction:', direction)
        console.log('右侧value:', value);
        console.log('movedKeys:', movedKeys)
      }
    }
  }
</script>
<style>
  .transfer-footer {
    margin-left: 20px;
    padding: 6px 5px;
  }
</style>

